import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutterroom/pages/home/info/home_room_list.dart';
import 'package:flutterroom/pages/home/widgets/common_swiper.dart';
import 'package:flutterroom/pages/my/data/room_peizhi.dart';
import 'package:flutterroom/pages/my/widget/my_add_room_title.dart';
import 'package:flutterroom/pages/room_detail/data/room_detail_data.dart';
import 'package:flutterroom/widgets/common_tag.dart';
import 'package:share/share.dart';

class RoomDetailWidget extends StatefulWidget {
  final String roomId;

  const RoomDetailWidget({Key key, this.roomId}) : super(key: key);

  @override
  _RoomDetailWidgetState createState() => _RoomDetailWidgetState();
}

class _RoomDetailWidgetState extends State<RoomDetailWidget> {
  RoomDetailData data;
  bool isLick = false;

  bool showAllText = true;

  @override
  void initState() {
    super.initState();
    data = defaultData;
  }

  Widget _bottomBtnWidget() {
    return Container(
      padding: EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 20),
      color: Colors.grey[200],
      child: Row(
        children: <Widget>[
          GestureDetector(
            onTap: () {
              setState(() {
                isLick = !isLick;
              });
            },
            child: Container(
              height: 50,
              width: 40,
              margin: EdgeInsets.only(right: 10),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Icon(
                    isLick ? Icons.star : Icons.star_border,
                    color: isLick ? Colors.green : Colors.grey,
                  ),
                  Text(
                    isLick ? "已收藏" : "收藏",
                    style: TextStyle(fontSize: 12),
                  )
                ],
              ),
            ),
          ),
          Expanded(
            child: GestureDetector(
              onTap: () {},
              child: Container(
                height: 50,
                margin: EdgeInsets.only(right: 5),
                decoration: BoxDecoration(
                    color: Colors.cyan, borderRadius: BorderRadius.circular(6)),
                child: Center(
                    child: Text(
                  "联系房东",
                  style: TextStyle(color: Colors.white),
                )),
              ),
            ),
          ),
          Expanded(
            child: GestureDetector(
              onTap: () {},
              child: Container(
                height: 50,
                margin: EdgeInsets.only(right: 5),
                decoration: BoxDecoration(
                    color: Colors.green,
                    borderRadius: BorderRadius.circular(6)),
                child: Center(
                    child: Text(
                  "预约看房",
                  style: TextStyle(color: Colors.white),
                )),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _roomSize(String size) {
    return Container(
      width: ScreenUtil().setWidth(750 - 1) / 2 - 10,
      child: Text(
        size,
        style: TextStyle(fontSize: 15),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    if (data.title == null) return Container();
    bool showTextTool = data.subTitle.length > 100;
    return Scaffold(
      appBar: AppBar(
        title: Text(data.title),
        actions: <Widget>[
          IconButton(
              icon: Icon(Icons.share),
              onPressed: () {
                Share.share("https://www.baidu.com");
              })
        ],
      ),
      body: Stack(
        children: <Widget>[
          Container(
            child: ListView(
              children: <Widget>[
                CommonSwiper(
                  images: data.houseImgs,
                ),
                AddRoomTitle(title: data.title),
                Container(
                  padding:
                      EdgeInsets.only(left: 10, right: 10, bottom: 2, top: 2),
                  child: Row(
                    children: <Widget>[
                      Text(
                        data.price.toString(),
                        style: TextStyle(color: Colors.pink, fontSize: 18),
                      ),
                      Text(
                        "元/月(押一付三)",
                        style: TextStyle(color: Colors.pink, fontSize: 14),
                      )
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(left: 10, right: 10, bottom: 5),
                  child: Wrap(
                    spacing: 4,
                    children: data.tags.map((item) => CommonTag(item)).toList(),
                  ),
                ),
                Divider(
                  color: Colors.grey,
                  indent: 10,
                  endIndent: 10,
                ),
                Container(
                  padding: EdgeInsets.only(left: 10, right: 10, top: 6),
                  child: Wrap(
                    runSpacing: 20,
                    children: <Widget>[
                      _roomSize("面积：${data.size}"),
                      _roomSize("楼层：${data.floor}"),
                      _roomSize("房型：${data.roomType}"),
                      _roomSize("装修：精装"),
                    ],
                  ),
                ),
                AddRoomTitle(title: "房源配置"),
                RoomDetailApplicance(
                  list: data.applicances,
                ),
                AddRoomTitle(title: "房源概况"),
                Container(
                  padding:
                      EdgeInsets.only(left: 10, right: 10, top: 4, bottom: 4),
                  child: Column(
                    children: <Widget>[
                      Text(data.subTitle ,maxLines:!showAllText?null:5 ?? "暂无房屋概况"),
                      Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            GestureDetector(
                              onTap: () {
                                setState(() {
                                  showAllText = !showAllText;
                                });
                              },
                              child: Container(
                                child: showTextTool
                                    ? Row(
                                        children: <Widget>[
                                          Text(showAllText ? "展开" : "收起"),
                                          Icon(showAllText
                                              ? Icons.keyboard_arrow_down
                                              : Icons.keyboard_arrow_up),
                                        ],
                                      )
                                    : Container(),
                              ),
                            ),
                            Text("举报")
                          ])
                    ],
                  ),
                ),
                AddRoomTitle(title: "猜你喜欢"),
                Info(showTitle: false),
                Padding(padding: EdgeInsets.all(40)),
              ],
            ),
          ),
          Positioned(
              width: ScreenUtil().setWidth(750),
              height: 90,
              bottom: 0,
              child: _bottomBtnWidget()),
        ],
      ),
    );
  }
}
